package com.twb.system.controller;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.twb.auth.common.LoginUserUtil;
import com.twb.core.base.Result;
import com.twb.core.base.controller.BaseController;
import com.twb.core.base.entity.TwbPageInfo;
import com.twb.core.security.annotation.Auth;
import com.twb.core.util.BeanUtils;
import com.twb.core.util.Results;
import com.twb.system.entity.importExport.ImportExport;
import com.twb.system.entity.importExport.dto.GetImportExportByIdDto;
import com.twb.system.entity.importExport.dto.SearchImportExportDto;
import com.twb.system.entity.importExport.vo.SaveImportExportVo;
import com.twb.system.entity.importExport.vo.SearchImportExportVo;
import com.twb.system.service.IImportExportService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * @Title  ImportExportController
 * @Description 异步导入导出记录表
 * 
 * @author DHL
 * @date 2021-08-09 09:39:11
 */
@RestController
@RequestMapping("/system/importExport")
@Api(tags = "异步导入导出记录表", value = "ImportExportController")
public class ImportExportController extends BaseController {
	@Autowired
	IImportExportService importExportService;

	/**
	 * @Title  search
	 * @Description 分页查询
	 * @param vo
	 * @return
	 * @author DHL
	 * @date 2021-08-09 09:39:11
	 */
	@Auth(verifyToken = true, verifyURL = false)
	@GetMapping("/search")
	@ApiOperation(value = "分页查询")
	public Result<TwbPageInfo<SearchImportExportDto>> search(SearchImportExportVo vo) {

		if (!LoginUserUtil.isDeveloper() && !LoginUserUtil.isSuperAdminUser()) {
			vo.setCreatorId(getLoginUser().getId());
		}

		TwbPageInfo<SearchImportExportDto> result = importExportService.searchImportExport(vo);
		return Results.successWithData(result);
	}

	/**
	 * @Title  getById
	 * @Description 根据ID获取详情
	 * @param id
	 * @return
	 * @author DHL
	 * @date 2021-08-09 09:39:11
	 */
	@Auth(verifyToken = true, verifyURL = false)
	@GetMapping("/getById")
	@ApiOperation(value = "根据ID获取详情")
	public Result<GetImportExportByIdDto> getById(@NotBlank @RequestParam @ApiParam(value = "主键", name = "id", required = true) String id) {
		ImportExport importExport = importExportService.getById(id);
		if (importExport == null) {
			return Results.failure("数据不存在");
		}
		GetImportExportByIdDto dto = new GetImportExportByIdDto();
		BeanUtils.copyNotNullProperties(importExport, dto);
		return Results.successWithData(dto);
	}

	/**
	 * @Title  save
	 * @Description 保存信息
	 * @param vo
	 * @return
	 * @author DHL
	 * @date 2021-08-09 09:39:11
	 */
	@Auth(verifyToken = true, verifyURL = false)
	@PostMapping("/save")
	@ApiOperation(value = "保存信息")
	public Result<ImportExport> save(@Valid SaveImportExportVo vo, HttpServletRequest request) {
		ImportExport result = importExportService.saveImportExport(vo, request);
		if (result != null) {
			return Results.successWithData(result, "操作成功");
		} else {
			return Results.failure("操作失败");
		}
	}

	/**
	 * @Title  updateById
	 * @Description 更新信息
	 * @param vo
	 * @return
	 * @author DHL
	 * @date 2021-08-09 09:39:11
	 */
//	@Auth(verifyToken = true)
//	@PutMapping("/updateById")
//	@ApiOperation(value="更新信息")
//	public Result<String> updateById(@Valid UpdateImportExportByIdVo vo){
//		int result = importExportService.updateImportExportById(vo);
//		if(result>0) {
//			return Results.success("更新成功");
//		}else {
//			return Results.failure("更新失败");
//		}
//	}

	/**
	 * @Title  deleteById
	 * @Description 删除信息
	 * @param id
	 * @return
	 * @author DHL
	 * @date 2021-08-09 09:39:11
	 */
//	@Auth(verifyToken = true)
//	@PostMapping("/deleteById")
//	@ApiOperation(value="删除信息")
//	public Result<String> deleteById(
//			@NotBlank
//			@RequestParam
//			@ApiParam(value="主键",name="id",required=true)
//			String id){
//		int result = importExportService.deleteImportExportById(id);
//		if(result>0) {
//			return Results.success("删除成功");
//		}else {
//			return Results.failure("删除失败");
//		}
//	}

	/**
	 * @Title  deleteBatchByIds
	 * @Description 批量删除信息
	 * @param ids
	 * @return
	 * @author DHL
	 * @date 2021-08-09 09:39:11
	 */
//	@Auth(verifyToken = true)
//	@PostMapping("/batchDeleteByIds")
//	@ApiOperation(value="批量删除信息")
//	public Result<String> deleteBatchByIds(
//			@NotBlank
//			@RequestParam
//			@ApiParam(value="主键集合",name="id",required=true)
//			String ids){
//		int result = importExportService.deleteImportExportByIds(ids);
//		if(result>0) {
//			return Results.success("删除成功");
//		}else {
//			return Results.failure("删除失败");
//		}
//	}

	/**
	 * @Title  logicDeleteById
	 * @Description 逻辑删除信息
	 * @param id
	 * @return
	 * @author DHL
	 * @date 2021-08-09 09:39:11
	 */
//	@Auth(verifyToken = true)
//	@PostMapping("/logicDeleteById")
//	@ApiOperation(value = "逻辑删除信息")
//	public Result<String> logicDeleteById(
//			@NotBlank
//			@RequestParam
//			@ApiParam(value="主键",name="id",required=true)
//			String id){
//		ImportExport record = importExportService.get(id);
//		if(null == record) {
//			return Results.failure("信息不存在");
//		}
//		record = new ImportExport();
//		record.setId(id);
//		importExportService.setUpdateInfo(record);
//		record.setIsdel(1);
//		int result = importExportService.updateSelective(record);
//		if(result>0) {
//			return Results.success("删除成功");
//		}else {
//			return Results.failure("删除失败");
//		}
//	}

	/**
	 * @Title  logicBatchDeleteByIds
	 * @Description 批量逻辑删除
	 * @param ids
	 * @return
	 * @author DHL
	 * @date 2021-08-09 09:39:11
	 */
//	@Auth(verifyToken = true)
//	@PostMapping("/logicBatchDeleteByIds")
//	@ApiOperation(value = "逻辑删除信息")
//	public Result<String> logicBatchDeleteByIds(
//			@NotBlank
//			@RequestParam
//			@ApiParam(value="主键集合",name="id",required=true)
//			String ids){
//		int result = importExportService.logicBatchDeleteImportExportByIds(ids);
//		if(result>0) {
//			return Results.success("删除成功");
//		}else {
//			return Results.failure("删除失败");
//		}
//	}

	/**
	 * @Title  exportExcel
	 * @Description 导出excel
	 * @param exportExcelVo
	 * @param searchVo
	 * @param request
	 * @return
	 * @author DHL
	 * @date 2021-08-09 09:39:11
	 */
//	@Auth(verifyURL=false)
//	@GetMapping("/exportExcel")
//	@ApiOperation(value="导出excel")
//	public void exportExcel(SearchTwbDataDicVo vo, HttpServletResponse response){
//		importExportService.exportExcel(vo, response);
//	}
}